import struct

from ..base import BaseParser


class GetSecurityCountCmd(BaseParser):

    def setParams(self, market):
        pkg = bytearray.fromhex(u'0c 0c 18 6c 00 01 08 00 08 00 4e 04')
        pkg.extend(struct.pack('<H', market))
        pkg.extend(b'\x75\xc7\x33\x01')

        # todo 尝试替换
        # pkg.extend(bytearray.fromhex('75 c7 33 01'))

        self.send_pkg = pkg

    def parseResponse(self, body_buf):
        (num,) = struct.unpack('<H', body_buf[:2])

        return num
